<?php
declare(strict_types=1);

namespace app\admin\service;

use app\admin\model\MarketingPath as MarketingPathModel;

class MarketingPathService
{
    /**
     * 活动文件
     * @param $where
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getMarketingPath($where)
    {
        $marketingPath = MarketingPathModel::getMarketingPath($where);
        $filesPath = '';
        $yFilesArr = [];
        foreach ($marketingPath as $k => $v) {
            $filesPath .= $v['path'] . ',';
            $marketingPath[$k]['basename'] = basename(parse_url($v['path'])['path']);
            $yFilesArr[] = $v['path'];
        }

        $path['filesPath'] = rtrim($filesPath, ',');
        $path['marketingPath'] = $marketingPath;

        return ['path' => $path, 'yFilesArr' => $yFilesArr];
    }

    /**
     * 创建活动文件路径
     * @param $data
     * @return MarketingPathModel|\think\Model
     */
    public static function createMarketingPath($data)
    {
        return MarketingPathModel::createMarketingPath($data);
    }

    /**
     * 删除活动文件路径
     * @param $where
     * @return bool
     */
    public static function delMarketingPath($where)
    {
        return MarketingPathModel::delMarketingPath($where);
    }
}